package P028_IntegerPool;

import java.util.Scanner;

/**
 * 优先使用整型池
 * 通过包装类的valueOf方法生成包装实例可以显著提高空间和时间性能
 */
public class IntegerPool {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            Integer i = new Integer(num);
            Integer j = new Integer(num);
            System.out.println("new 产生的对象比较:" + (i == j));

            i = num;
            j = num;
            System.out.println("基本类型转换产生的对象比较:" + (i == j));

            i = Integer.valueOf(num);
            j = Integer.valueOf(num);
            System.out.println("valueOf产生的对象比较:" + (i == j));
        }
    }
}
